/*
 * dbl_list.h
 *
 *  Created on: 06/06/2012
 *      Author: Roy
 */

#ifndef DBL_LIST_H_
#define DBL_LIST_H_
/** Type used for returning error codes from list functions */
#include "nlock.h"
#include "stdbool.h"


typedef enum ListResult_t {
	LIST_SUCCESS,
	LIST_NULL_ARGUMENT,
	LIST_OUT_OF_MEMORY,
	LIST_INVALID_CURRENT,
	LIST_NO_SUCH_ELEMENT,
} ListResult;

typedef void* ListElement;

typedef ListElement (*CopyListElement)(ListElement);

typedef void (*FreeListElement)(ListElement);



typedef struct Node_t{
	struct Node_t* next;
	struct Node_t* previous;
	ListElement data;
}*Node;

typedef struct List_t{
	Node head;
	Node tail;
	Node current;
	int listSize;
	CopyListElement copy;
	FreeListElement freeElement;
}*List;


List listCreate(CopyListElement copyElement, FreeListElement freeElement);

int listGetSize(List list);

ListElement listGetFirst(List list);
ListElement listGetNext(List list);
ListElement listGetCurrent(List list);
ListResult listInsertFirst(List list, ListElement element);
ListResult listRemoveCurrent(List list);
ListResult listClear(List list);
void listDestroy(List list);
ListResult listInsertLast(List list, ListElement element);



typedef struct node_type{
	struct node_type* next;
	struct node_type* prev;
	int key;
	char val;
	nlock* lock;
}*list_node;

typedef struct dbl_list{
	list_node head;
	list_node tail;
	List zombies;
} *list;

void Initialize();

void Destroy();

bool InsertHead(int key, char data);

bool InsertTail(int key, char data);

bool Delete(int key);

bool Search(int key, char* data);

#endif /* DBL_LIST_H_ */
